package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.auth.ChangePwdByEmailDto;
import com.team.recruitment_management_system.pojo.dto.auth.EmailAndCaptchaDto;
import com.team.recruitment_management_system.pojo.dto.auth.LoginDto;
import com.team.recruitment_management_system.pojo.dto.auth.RegisterDto;
import com.team.recruitment_management_system.pojo.vo.LoginVo;
import com.team.recruitment_management_system.security.OperationLogAnnotation;
import com.team.recruitment_management_system.service.AuthService;
import com.team.recruitment_management_system.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
@Tag(name = "1.认证模块")
public class AuthController {
    @Autowired
    private AuthService authService;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    @OperationLogAnnotation(operModul = "认证模块-注册接口",operType = "插入", operDesc = "Post请求,用户注册")
    public Result<LoginVo> userRegister(@RequestBody @Validated RegisterDto registerDto){
        return authService.userRegister(registerDto);
    }

    @PostMapping("/login/pwd")
    @Operation(summary = "用户登录")
    @OperationLogAnnotation(operModul = "认证模块-用户登录",operType = "插入", operDesc = "Post请求,用户登录")
    public Result<LoginVo> userLogin(@RequestBody @Validated LoginDto loginDto) {
        return authService.userLogin(loginDto);
    }

    @PostMapping("/login/email")
    @Operation(summary = "用户邮箱登录")
    @OperationLogAnnotation(operModul = "认证模块-用户邮箱登录",operType = "插入", operDesc = "Post请求,用户邮箱登录")
    public Result<LoginVo> userLoginByEmail(@RequestBody @Validated EmailAndCaptchaDto emailAndCaptchaDto) {
        return authService.userLoginByEmail(emailAndCaptchaDto);
    }

    @PutMapping("/change/pwd/byEmail")
    @Operation(summary = "忘记密码-通过邮箱修改密码")
    @OperationLogAnnotation(operModul = "认证模块-邮箱修改密码",operType = "修改", operDesc = "put请求,邮箱修改密码")
    public Result<Void> changeUserPwdByEmail(@RequestBody @Validated ChangePwdByEmailDto changePwdByEmailDto) {
        return authService.userChangePwdByEmail(changePwdByEmailDto);
    }
}
